package com.kartoshka.core.hard 
{
	import com.kartoshka.interfaces.IUIDisplayObject;

	import flash.events.Event;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;

	/**
	 * @author Alexander Zats, 2009
	 */
	public class UIMovieClip extends MovieClip 
	{

		private var _parent : DisplayObjectContainer;

		public function UIMovieClip()
		{
			this.addEventListener( Event.ADDED, onParentChange, false, 0, true );
			this.addEventListener( Event.REMOVED, onParentChange, false, 0, true );
		}

		private function onParentChange(event : Event) : void
		{
			if ( event.target != this ) return;
			if ( ! super.parent ) _parent = null;
			else if ( ! (super.parent is IUIDisplayObject) && ( super.parent.parent is IUIDisplayObject ) ) _parent = super.parent.parent;
			else _parent = super.parent;
		}

		override public function get parent() : DisplayObjectContainer
		{
			return _parent;
		}
	}
}
